package jiyun.com.yiyanmeng;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;

import adapter.BooksDatilAdaper;
import base.BaseActivity;
import bean.BooksDatilBean;
import cn.bingoogolapple.badgeview.BGABadgeTextView;
import jiyun.com.yiyanmeng.http.MyWebView;
import presenter.BooksDatilPresenter;
import view.BooksDatilView;

public class BooksDatilActivity extends BaseActivity<BooksDatilView, BooksDatilPresenter> implements BooksDatilView, View.OnClickListener {

    private TextView mFan;
    /**
     * 返回
     */
    private TextView mImageBack;
    /**
     * 商品详情
     */
    private TextView mTvTitle;
    private RelativeLayout mRl;
    private FrameLayout mRlMain;
    private XRecyclerView mRecyclerView;
    private ImageView mIvInshop;
    private BGABadgeTextView mTvMsgNum;
    /**
     * 购物车
     */
    private TextView mTvInshop;
    private RelativeLayout mFlInshop;
    private ImageView mIvFollow2;
    /**
     * 收藏
     */
    private TextView mTvFollow2;
    private RelativeLayout mFlFollow2;
    /**
     * 加入购物车
     */
    private TextView mTvAddCart;
    /**
     * 立即购买
     */
    private TextView mTvQuickBuy;
    private LinearLayout mRl3;
    private String id;
    private ArrayList<BooksDatilBean.ShopBean> shopBeans;
    private ArrayList<BooksDatilBean.ShopBean> banners;
    private BooksDatilAdaper datilAdaper;
    private WebView mWebView;
    private BooksDatilBean.ShopBean shop;


    @Override
    protected BooksDatilPresenter createPresenter() {
        return new BooksDatilPresenter();
    }

    @Override
    protected int bindLayoutId() {
        return R.layout.activity_books_datil;
    }

    @Override
    public void showToast(String msg) {

    }

    @Override
    protected void initData() {
        id = getIntent().getStringExtra("id");
        mPresenter.loadData(Integer.parseInt(id));
    }

    @Override
    protected void setListener() {

    }

    public void initView() {
        mFan = (TextView) findViewById(R.id.fan);
        mImageBack = (TextView) findViewById(R.id.image_back);
        mTvTitle = (TextView) findViewById(R.id.tv_title);
        mRl = (RelativeLayout) findViewById(R.id.rl);
        mRlMain = (FrameLayout) findViewById(R.id.rl_main);
        mRecyclerView = (XRecyclerView) findViewById(R.id.recyclerView);
        mIvInshop = (ImageView) findViewById(R.id.iv_inshop);
        mTvMsgNum = (BGABadgeTextView) findViewById(R.id.tv_msgNum);
        mRl = (RelativeLayout) findViewById(R.id.rl);
        mTvInshop = (TextView) findViewById(R.id.tv_inshop);
        mFlInshop = (RelativeLayout) findViewById(R.id.fl_inshop);
        mIvFollow2 = (ImageView) findViewById(R.id.iv_follow2);
        mTvFollow2 = (TextView) findViewById(R.id.tv_follow2);
        mFlFollow2 = (RelativeLayout) findViewById(R.id.fl_follow2);
        mTvAddCart = (TextView) findViewById(R.id.tv_add_cart);
        mTvQuickBuy = (TextView) findViewById(R.id.tv_quick_buy);
        mTvQuickBuy.setOnClickListener(this);
        mRl3 = (LinearLayout) findViewById(R.id.rl3);
        mWebView = (WebView) findViewById(R.id.webView);
        mRecyclerView.setPullRefreshEnabled(false);
        mRecyclerView.setLoadingMoreEnabled(false);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        shopBeans = new ArrayList<>();
        banners = new ArrayList<>();
        datilAdaper = new BooksDatilAdaper(this, banners, shopBeans);
        mRecyclerView.setAdapter(datilAdaper);
        mFan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }


    @Override
    public void onSuccess(BooksDatilBean datilBean) {
        shop = datilBean.getShop();
        String xiang_qing = shop.getXiang_qing();
        Log.i("xiang_qing", xiang_qing);
        mWebView.loadUrl(xiang_qing);
        shopBeans.add(shop);
        banners.add(shop);
        datilAdaper.notifyDataSetChanged();
    }

    @Override
    public void onFailed(String str) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_quick_buy:
                ArrayList<BooksDatilBean> beans = new ArrayList<>();
                Intent intent = new Intent(this,TiJiaoActivity.class);
                startActivity(intent);
                break;
        }
    }
}
